package org.tinygroup.channel.protocol.impl;

import java.util.List;

import org.tinygroup.channel.protocol.ProtocolInInterface;
import org.tinygroup.channel.protocol.ProtocolListener;
import org.tinygroup.context.Context;
import org.tinygroup.context.util.ContextFactory;

public abstract class AbstractProtocolInInterface<Request, Response> extends
		AbstractProtocolInterface<Request, Response> implements
		ProtocolInInterface<Request, Response>{

	public Response received(Request r) {
		List<ProtocolListener<?,?>> listeners = getListeners();
		ProtocolListenerChain chain = new ProtocolListenerChain(listeners);
		Context context = ContextFactory.getContext();
		chain.pre(r, context);
		Response response = realDeal(r,context);
		chain.post(r,response, context);
		return response;
	}
	protected abstract Response realDeal(Request r,Context context);
	
	

}
